package com.coocaa.cirrus.common.base.model;

import com.coocaa.cirrus.common.base.enums.HttpResponseEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author bijiahao
 * @date : 2025/10/21 17:14
 * @description
 */
@Data
public class RespBase<T> implements Serializable {
    private String result;
    private int code;
    private T data;
    private String msg;

    public String getResult() {
        return this.result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return this.data;
    }

    public RespBase<T> setData(T data) {
        this.data = data;
        return this;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public RespBase<T> setSuccessResult() {
        return this.setSuccessResult(HttpResponseEnum.SYSTEM_SUCCESS.getCode(), HttpResponseEnum.SYSTEM_SUCCESS.getResult(), HttpResponseEnum.SYSTEM_SUCCESS.getMsg());
    }

    public RespBase<T> setSuccessResult(String msg) {
        return this.setSuccessResult(HttpResponseEnum.SYSTEM_SUCCESS.getCode(), HttpResponseEnum.SYSTEM_SUCCESS.getResult(), msg);
    }

    public RespBase<T> setSuccessResult(int code, String result, String msg) {
        return this.setResult(code, result, msg);
    }

    public RespBase<T> setFailResult() {
        return this.setFailResult(HttpResponseEnum.SYSTEM_FAILED.getCode(), HttpResponseEnum.SYSTEM_FAILED.getResult(), HttpResponseEnum.SYSTEM_FAILED.getMsg());
    }

    public RespBase<T> setFailResult(String msg) {
        return this.setFailResult(HttpResponseEnum.SYSTEM_FAILED.getCode(), HttpResponseEnum.SYSTEM_FAILED.getResult(), msg);
    }

    public RespBase<T> setFailResult(int code, String result, String msg) {
        return this.setResult(code, result, msg);
    }

    private RespBase<T> setResult(int code, String result, String msg) {
        this.setResult(result);
        this.setCode(code);
        this.setMsg(msg);
        return this;
    }

    private RespBase<T> setResult(int code, String msg) {
        this.setResult(this.result);
        this.setCode(code);
        this.setMsg(msg);
        return this;
    }

    public boolean success() {
        return this.code == HttpResponseEnum.SYSTEM_SUCCESS.getCode();
    }
}
